String.prototype.toDate = function() {
	return new Date(Date.parse(this.replace(/-/g, "/")));

}

String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {   
	 
	　 if (!RegExp.prototype.isPrototypeOf(reallyDo)) {   
	 
	        return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);   
	 
	    } else {   
	 
	        return this.replace(reallyDo, replaceWith);   
	 
	    }  
	 
}

Date.prototype.format = function (formatStr) {    
    var date = this;    
    /*
	 * 函数：填充0字符 参数：value-需要填充的字符串, length-总长度 返回：填充后的字符串
	 */   
    var zeroize = function (value, length) {    
        if (!length) {    
            length = 2;    
        }    
        value = new String(value);    
        for (var i = 0, zeros = ''; i < (length - value.length); i++) {    
            zeros += '0';    
        }    
            return zeros + value;    
    };    
    return formatStr.replace(/"[^"]*"|'[^']*'|\b(?:d{1,4}|M{1,4}|yy(?:yy)?|([hHmstT])\1?|[lLZ])\b/g, function($0) {    
        switch ($0) {    
            case 'd': return date.getDate();    
            case 'dd': return zeroize(date.getDate());    
            case 'ddd': return ['Sun', 'Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat'][date.getDay()];    
            case 'dddd': return ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][date.getDay()];    
            case 'M': return date.getMonth() + 1;    
            case 'MM': return zeroize(date.getMonth() + 1);    
            case 'MMM': return ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][date.getMonth()];    
            case 'MMMM': return ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][date.getMonth()];    
            case 'yy': return new String(date.getFullYear()).substr(2);    
            case 'yyyy': return date.getFullYear();    
            case 'h': return date.getHours() % 12 || 12;    
            case 'hh': return zeroize(date.getHours() % 12 || 12);    
            case 'H': return date.getHours();    
            case 'HH': return zeroize(date.getHours());    
            case 'm': return date.getMinutes();    
            case 'mm': return zeroize(date.getMinutes());    
            case 's': return date.getSeconds();    
            case 'ss': return zeroize(date.getSeconds());    
            case 'l': return date.getMilliseconds();    
            case 'll': return zeroize(date.getMilliseconds());    
            case 'tt': return date.getHours() < 12 ? 'am' : 'pm';    
            case 'TT': return date.getHours() < 12 ? 'AM' : 'PM';    
        }    
    });    
} 


function formatNum(num, cent, isThousand) {
	num = num+"";
	num = num.toString().replace(/\$|\,/g, '');
	if (isNaN(num))// 检查传入数值为数值类型.
		num = "0";
	if (isNaN(cent))// 确保传入小数位为数值型数值.
		cent = 0;
	cent = parseInt(cent);
	cent = Math.abs(cent);// 求出小数位数,确保为正整数.
	if (isNaN(isThousand))// 确保传入是否需要千分位为数值类型.
		isThousand = 0;
	isThousand = parseInt(isThousand);
	if (isThousand < 0)
		isThousand = 0;
	if (isThousand >= 1) // 确保传入的数值只为0或1
		isThousand = 1;
	sign = (num == (num = Math.abs(num)));// 获取符号(正/负数)
	// Math.floor:返回小于等于其数值参数的最大整数
	num = Math.floor(num * Math.pow(10, cent) + 0.50000000001);// 把指定的小数位先转换成整数.多余的小数位四舍五入.
	cents = num % Math.pow(10, cent); // 求出小数位数值.
	num = Math.floor(num / Math.pow(10, cent)).toString();// 求出整数位数值.
	cents = cents.toString();// 把小数位转换成字符串,以便求小数位长度.
	while (cents.length < cent) {// 补足小数位到指定的位数.
		cents = "0" + cents;
	}
	if (isThousand == 0) // 不需要千分位符.
		return (((sign) ? '' : '-') + num + '.' + cents);
	// 对整数部分进行千分位格式化.
	for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
		num = num.substring(0, num.length - (4 * i + 3)) + ','
				+ num.substring(num.length - (4 * i + 3));

	if (cent == 0) {
		return (((sign) ? '' : '-') + num);
	} else {
		return (((sign) ? '' : '-') + num + '.' + cents);
	}

}

function secondToTime(time){
	var days = Math.floor(time / 1440 / 60);
	var hours = Math.floor((time - days * 1440 * 60) / 3600);
	var minutes = Math.floor((time - days * 1440 * 60 - hours * 3600) / 60);
	var seconds = (time - days * 1440 * 60 - hours * 3600 - minutes *60);
	return days+"日"+hours+"时"+minutes +"分"+seconds+"秒";
}

